ValidatedSet

open class ValidatedSet<T>(defaultValue: Set<T>, entryHandler: Entry<T, *>) : ValidatedField<Set<T>> , Set<T>

a validated set

This ValidatedField implements Set, so you can directly use it as if it were an immutable list

Author

fzzyhmstrs

Since

0.2.0

Parameters

T

any non-null type

defaultValue

default set of values

entryHandler

Entry used to handle individual set entries

Samples

import me.fzzyhmstrs.fzzy_config.util.EnumTranslatable
import me.fzzyhmstrs.fzzy_config.validation.Shorthand.validated
import me.fzzyhmstrs.fzzy_config.validation.collection.*
import me.fzzyhmstrs.fzzy_config.validation.minecraft.ValidatedIdentifier
import me.fzzyhmstrs.fzzy_config.validation.misc.ValidatedBoolean
import me.fzzyhmstrs.fzzy_config.validation.misc.ValidatedString
import me.fzzyhmstrs.fzzy_config.validation.number.ValidatedInt
import net.minecraft.registry.RegistryKeys
import net.minecraft.util.Identifier

fun main() { 
   //sampleStart 
   //validated set, based on TestEnum, validation limiting to those keys
val validatedSet = ValidatedSet(setOf(KeyEnum.KEY_1), KeyEnum::class.java.validated())

//wraps the vararg valued provided with a blank validated field (identifiers in this case). validation with actual bounds and logic can of course be used too
val setFromFieldArg = ValidatedIdentifier().toSet(Identifier.of("stick"), Identifier.of("blaze_rod"))

//wraps the collection provided with a blank validated field (identifiers in this case). validation with actual bounds and logic can of course be used too
val setFromFieldCollection = ValidatedIdentifier().toSet(setOf(Identifier.of("wooden_sword"), Identifier.of("stone_sword")))

//fields and sections have lang keys based on their "location" in the Config class graph.
//Lange key composition is as follows
//1. the namespace of the config id: (my_mod)
//2. the path of the config id: (my_mod.my_config)
//3. any parent ConfigSection field names as declared in-code: (my_mod.my_config.subSection)
//4. the setting field name as declared in-code: (my_mod.my_config.subSection.fieldName)
val fieldLang = """
{
    "_comment1": "the lang for an example 'fieldName' setting in a config inside section 'subSection'",
    "my_mod.my_config.subSection.fieldName": "Very Important Setting",
    "my_mod.my_config.subSection.fieldName.desc": "This very important setting is used in this very important way."
}
""" 
   //sampleEnd
}

Constructors

Link copied to clipboard
constructor(defaultValue: Set<T>, entryHandler: Entry<T, *>)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard
open override val size: Int

Functions

Link copied to clipboard
open override fun accept(input: Set<T>)

updates the wrapped value. NOTE: this method will push updates to an UpdateManager, if any. For in-game updating consider validateAndSet

Link copied to clipboard
open fun addListener(listener: Consumer<ValidatedField<Set<T>>>)

Attaches a listener to this field. This listener will be called any time the field is written to ("set"). accept, validateAndSet, setAndUpdate and so on will all call the listener.

Link copied to clipboard
open fun andThen(p0: Consumer<in Set<T>>): Consumer<Set<T>>
Link copied to clipboard
fun codec(): Codec<Set<T>>

Provides a Codec representing the value type of this validation, backed by the validators within as applicable

Link copied to clipboard
open operator override fun contains(element: T): Boolean
Link copied to clipboard
open override fun containsAll(elements: Collection<T>): Boolean
Link copied to clipboard
open override fun copyStoredValue(): Set<T>

Creates a deep copy of the stored value and returns it

Link copied to clipboard
open fun description(fallback: String? = null): MutableText

The translated Text description from the descriptionKey. Falls back to an empty string so no tooltip is rendered.

Link copied to clipboard
open override fun descriptionKey(): String

translation key of this Translatable's description. the "description" in-game, the descriptions Enchantment Descriptions adds to enchantment tooltips are a good example.

Link copied to clipboard
open fun forEach(p0: Consumer<in T>)
Link copied to clipboard
open override fun get(): Set<T>

supplies the wrapped value

Link copied to clipboard
fun getDefault(): Set<T>

Provides this validations default value

Link copied to clipboard

Whether this Translatable has a valid description

Link copied to clipboard

Whether this Translatable has a valid translation

Link copied to clipboard
open override fun instanceEntry(): ValidatedSet<T>

creates a deep copy of this ValidatedSet return ValidatedSet wrapping a deep copy of the currently stored set and passes the entry handlers

Link copied to clipboard
open override fun isEmpty(): Boolean
Link copied to clipboard
open operator override fun iterator(): Iterator<T>
Link copied to clipboard
fun <N> map(to: Function<Set<T>, out N>, from: Function<in N, Set<T>>): ValidatedField<N>

Maps this validation to a new convertible type. The default value will be applied from this delegates current storedValue

fun <N> map(defaultValue: N, to: Function<Set<T>, out N>, from: Function<in N, Set<T>>): ValidatedField<N>
fun <N> map(to: Function<Set<T>, out N>, from: Function<in N, Set<T>>, defaultValue: Set<T>): ValidatedField<N>

Maps this validation to a new convertible type.

Link copied to clipboard
open fun parallelStream(): Stream<T>
Link copied to clipboard
open override fun spliterator(): Spliterator<T>
Link copied to clipboard
open fun stream(): Stream<T>
Link copied to clipboard
open fun <T : Any> toArray(p0: IntFunction<Array<T>>): Array<T>
Link copied to clipboard
fun toChoices(widgetType: ValidatedChoice.WidgetType = ValidatedChoice.WidgetType.POPUP, translationProvider: BiFunction<T, String, MutableText> = BiFunction { t, _ -> t.transLit(t.toString()) }, descriptionProvider: BiFunction<T, String, Text> = BiFunction { t, _ -> t.descLit("") }): ValidatedChoice<T>

Converts this ValidatedSet into ValidatedChoice wrapping this set as the valid choice options

Link copied to clipboard
open fun toCondition(condition: ValidatedField<Boolean>, fallback: Supplier<Set<T>>): ValidatedCondition<Set<T>>

Convert this field to a ValidatedCondition using the provided validation as a supplier. The provided condition (and any others you append) must pass for the stored value to be provided, otherwise the fallback will be supplied.

open fun toCondition(condition: Supplier<Boolean>, failMessage: Text, fallback: Supplier<Set<T>>): ValidatedCondition<Set<T>>

Convert this field to a ValidatedCondition. The provided condition (and any others you append) must pass for the stored value to be provided, otherwise the fallback will be supplied.

open fun toCondition(scope: String, failMessage: Text, fallback: Supplier<Set<T>>): ValidatedCondition<Set<T>>

Convert this field to a ValidatedCondition using the provided scope with a default boolean provider. The provided condition (and any others you append) must pass for the stored value to be provided, otherwise the fallback will be supplied. The provided scope must point to a valid boolean config scope otherwise the initial condition will never pass.

Link copied to clipboard
fun toList(vararg elements: Set<T>): ValidatedList<Set<T>>

wraps the provided values into a ValidatedList with this field as validation

fun toList(collection: Collection<Set<T>>): ValidatedList<Set<T>>

wraps the provided collection into a ValidatedList with this field as validation

Link copied to clipboard
fun toSet(vararg elements: Set<T>): ValidatedSet<Set<T>>

wraps the provided values into a ValidatedSet with this field as validation

fun toSet(collection: Collection<Set<T>>): ValidatedList<Set<T>>

wraps the provided collection into a ValidatedList with this field as validation

Link copied to clipboard
open override fun translation(fallback: String?): MutableText

The translated Text name from the translationKey. Falls back to the implementing classes Simple Name (non-translated)

Link copied to clipboard
open override fun translationKey(): String

translation key of this Translatable. the "name" in-game

Link copied to clipboard
fun trySerialize(input: Any?, errorBuilder: MutableList<String>, flags: Byte): TomlElement?
Link copied to clipboard
open override fun trySet(input: Any?)
Link copied to clipboard
open fun update(updateMessage: Text)
Link copied to clipboard
open fun validateAndSet(input: Set<T>): ValidationResult<Set<T>>

A setter method for the storedValue that first validates the value being set and then stores the post-validation result.

Link copied to clipboard

Shorthand validated number Set

fun <T : Any> Set<T>.validated(handler: Entry<T, *>): ValidatedSet<T>

Shorthand validated Set

Link copied to clipboard
fun Set<Identifier>.validatedList(list: List<Identifier>): ValidatedSet<Identifier>

Shorthand Validated Identifier Set, validated with a list

Link copied to clipboard
fun <T : Any> Set<Identifier>.validatedRegistry(registry: Registry<T>): ValidatedSet<Identifier>

Shorthand Validated Identifier Set, validated with a registry

fun <T : Any> Set<Identifier>.validatedRegistry(registry: Registry<T>, predicate: BiPredicate<Identifier, RegistryEntry<T>>): ValidatedSet<Identifier>

Shorthand Validated Identifier Set, validated with a predicated registry

Link copied to clipboard
fun Set<Identifier>.validatedTag(tagKey: TagKey<*>): ValidatedSet<Identifier>

Shorthand Validated Identifier Set, validated with a tag

Link copied to clipboard
open fun widgetAndTooltipEntry(choicePredicate: ChoiceValidator<Set<T>> = ChoiceValidator.any()): ClickableWidget